package tgc.edu.tgq.demo.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import tgc.edu.tgq.demo.entity.SysUser;
import tgc.edu.tgq.demo.security.UserUtils;
import tgc.edu.tgq.demo.service.SysUserService;

@Controller
@RequestMapping(value = "/password")
public class PasswordController {
	@Autowired
	private SysUserService SysUserService;
	@Autowired
	private UserUtils userUtils;
	
	@RequestMapping(value = "/edit")
	public void edit() {
		
	}
	
	@RequestMapping("/save")
	@ResponseBody
	public String save(String password2) {
		SysUser user=userUtils.getUser();
		BCryptPasswordEncoder encoder=new BCryptPasswordEncoder();
		String password=encoder.encode(password2);
		user.setPassword(password);
		SysUserService.save(user);
		return "/login?logout";
	}
}
